package xin.common.file;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;
import xin.common.date.DateUtils;

import java.io.File;
import java.security.SecureRandom;

/**
 * <pre>
 * Abstract File Uploader
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2018/9/21
 */
public abstract class AbstractUploader implements Uploader{
    private SecureRandom secureRandom;


    public AbstractUploader(){
        secureRandom = new SecureRandom();
    }

    @Override
    public  String getFileName(MultipartFile imageFile){
        String fileDirectory = DateUtils.formatDate(DateUtils.YYYYMMDD) + File.separator + System.currentTimeMillis() + this.secureRandom.nextInt(6);
        return fileDirectory + File.separator + FilenameUtils.getExtension(imageFile.getOriginalFilename());
    }
}
